package com.mit.service.maintenance.dao.impl;

import java.util.List;

import com.mit.common.exception.NoRecordUpdateException;
import com.mit.common.maintenance.dto.PaymentDTO;
import com.mit.service.core.dao.AbstractDAO;
import com.mit.service.maintenance.dao.IPaymentDAO;

public class PaymentDAOImpl extends AbstractDAO implements IPaymentDAO {

	@Override
	public PaymentDTO createPayment(PaymentDTO paymentDTO) {
		Integer id = (Integer)  getSqlMapClientTemplate().insert("insertPayment", paymentDTO);
		paymentDTO.setId(id);
		return paymentDTO;
	}

	@Override
	public PaymentDTO updatePayment(PaymentDTO paymentDTO)
			throws NoRecordUpdateException {
		int rs = getSqlMapClientTemplate().update("updatePayment", paymentDTO);
		if (rs == 0) {
			throw new NoRecordUpdateException("No payment records!");
		}
		return paymentDTO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PaymentDTO> retrievePayments(int organizationId) {
		return getSqlMapClientTemplate().queryForList("selectPayments", organizationId);
	}

}
